/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package models;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.Temporal;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;


/**
 *
 * @author milokokok
 */
 
 
 
 @Entity
@Table(name="baskets", catalog="", schema="")
@NamedQueries({
    @NamedQuery(name="Baskets.getBaskets", query = "SELECT b FROM baskets b WHERE b.id = :id_baskets" ),
    @NamedQuery(name="Baskets.getOrders", query = "SELECT b FROM baskets b WHERE b.id_order = :id_order")
})
public class Baskets extends BaseEntity implements Serializable {
    private static final long serialVersionUID = 1L;
    
    @ManyToOne
    @Column(name="price")
    private double  price;
	
    @ManyToOne
    @JoinColumn(name="id_order", referencedColumnName="id")
    private Orders orders;
    @OneToMany(mappedBy="id_baskets")
    private List<ItemBasket> elementsList;
     

    
        
    
     public List<ItemBasket> getElementsList() {
        return elementsList;
    }
    
    
     public void setElementsList(List<ItemBasket> elementsList) {
        this.elementsList = elementsList;
    }
    
    
    public Orders getOrders() {
        return orders;
    }
    

    public void setOrder(Orders orders) {
        this.orders = orders;
    }
    
    
     
    public void addItemBasket(ItemBasket elementsList) {
        if (null == elementsList) return;
        if (null == this.elementsList) {
            this.elementsList = new ArrayList<ItemBasket>();
        }
        this.elementsList.add(elementsList);
    }
    
    public boolean deleteItemBasket(ItemBasket elementsList) {
        if (null != this.elementsList && null != elementsList) {
            return this.elementsList.remove(elementsList);
        } else {
            return false;
        }
    }
    
    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Orders)) {
            return false;
        }
        Orders other = (Orders) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "models.Orders[ id=" + id + " ]";
    }
    
}